<?php

namespace haibao\cms\business\activity;

use  \haibao\cms\data\activity\ActivityPrizeWinner  as ActivityPrizeWinnerData;
use \haibao\comment\business\BusinessException;
use \haibao\cms\business\activity\activity as ActivityBusiness;

class ActivityPrizeWinner extends \haibao\cms\business\Base{
    
    public static function getActivityPrizeWinnerList($filter,$isGetOne = TRUE){
        $activityData = new ActivityPrizeWinnerData();
        if($isGetOne){
            return $activityData->getOne($filter);
        }else{
            return $activityData->getAll($filter);
        }
    }
    
    public static function getActivityPrizeWinnerById($Id){
        if(!$Id){
            throw new BusinessException('Id不可以为空！');
        }
        $activityData = new ActivityPrizeWinnerData();
        return $activityData->getOneById($Id);
    }
    
    public static function updateActivityPrizeWinnerById($activityPrizeWinnerModel){
        \haibao\cms\business\Base::checkOperation(self::FUNC_CODE_ACTIVITY_PRIZE_WINNER_EDIT);
        self::checkModelData($activityPrizeWinnerModel);
        $activityData = new ActivityPrizeWinnerData;
        $activityData->updateById($activityPrizeWinnerModel->Id, $activityPrizeWinnerModel);
        ActivityBusiness::delActivityCache($activityPrizeWinnerModel->ActivityId);
        \haibao\cms\business\Base::saveOperateHistory(\haibao\cms\business\Base::FUNC_CODE_ACTIVITY_PRIZE_WINNER_EDIT, $activityPrizeWinnerModel->toArray(false));
    }
    
    private static function checkModelData($model){
        if(!$model->Id){
            throw new BusinessException('Id不可以为空！');
        }
        if(!$model->Keyword){
            throw new BusinessException('Keyword不可以为空！');
        }
        if(!$model->Name){
            throw new BusinessException('Name不可以为空！');
        }
        if(!$model->Mobile){
            throw new BusinessException('Mobile不可以为空！');
        }
        if(!$model->Address){
            throw new BusinessException('Address不可以为空！');
        }
    }
}